package com.xgame.server.netty.handler;


import com.xgame.server.constants.RpcEnums;
import com.xgame.server.handler.Handler;
import com.xgame.server.netty.enity.MsgEntity;
import com.xgame.server.netty.proto.Game;
import com.xgame.server.utils.HandlerRegister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class CmdHandler {

    private static final Logger logger = LoggerFactory.getLogger(CmdHandler.class);

    @Resource
    private HandlerRegister handlerRegister;

    public void handleMsg(MsgEntity msgEntity, List<MsgEntity> commandList) {

        String beanName = RpcEnums.getBeanName(msgEntity.getCmdCode());

        if(beanName == null){
            logger.error("Can't find bean，code={}",msgEntity.getCmdCode());
            return;
        }

        Handler handler = handlerRegister.getHandlerImpl(beanName);
        if(handler != null){
            handler.doHandler(msgEntity,commandList);
        }
    }

}
